package chances.system.operator.service;

import java.io.File;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

@Service
public class BaseService {

    private static final Logger logger = LoggerFactory.getLogger(BaseService.class);

    @Value("${site.picture:site-picture}")
    private Resource sitePictureFolder;
    
    protected File getSitePicturePath(String path) {
        try {
            return new File(sitePictureFolder.getFile(), path);
        } catch (Exception e) {
            logger.error(e.toString(), e);
            return null;
        }
    }

    public void removeSiteImage(String relPath){
        if(StringUtils.isNotBlank(relPath)){
            File image = getSitePicturePath(relPath);
            if(image.exists()){
                image.delete();
            }
        }
    }
    
    public void removeSiteImage(List<String> relPaths){
        for (String relPath : relPaths) {
            removeSiteImage(relPath);
        }
    }
}